#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <strings.h>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        cout << "Usage: - IP_messge - Port_messge" << endl;
    }

    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd < 0)
    {
        perror("socked failed !");
        exit(1);
    }
    struct sockaddr_in IPv4;                   // 设置网络描述表
    bzero(&IPv4, sizeof(IPv4));                // 初始化miaoshu
    IPv4.sin_family = AF_INET;                 // 设置网络通信
    IPv4.sin_addr.s_addr = inet_addr(argv[1]); // 设置ip
    IPv4.sin_port = htons(stoi(argv[2]));      // 设置duankouhao
    socklen_t len = sizeof(IPv4);
    while (true)
    {
        // 发送信息
        cout << "Please enter#";
        string line;
        getline(cin, line);
        sendto(sockfd, line.c_str(), sizeof(line), 0, (const struct sockaddr *)&IPv4,len);
    }
    return 0;
}